unsigned long timer;
int counter1=6;
int counter2=5;
int counter3=4;
long prev1=0;
long prev2=0;
long prev3=0;

void setup()
{
   Serial.begin(9600);
  
}
void loop ()
{
  f1();
  f2();
  f3();
}


void f1() {		

  long period1 = 1000;
  switch (counter1)
  {
  case 1: f1_a(counter1);
          counter1++;
          break;
  case 2: f1_b(counter1);
  	  counter1++;
	  break;
  case 3: f1_c(counter1);
	  counter1++;
	  break;
  case 4: f1_d(counter1);
	  counter1++;
	  break;
  case 5: f1_e(counter1);
  	  counter1++;
	  break;
  case 6: timer = millis()%100000;
	  if(timer - prev1>=period1) 
	  {
		counter1=1;
		prev1=timer;
	  }
	  break;
	}
}

	

void f2() {
  long period2=3000;
	
  switch (counter2)
  {
    case 1: f2_a(counter2);
            counter2++;
	    break;
    case 2: f2_b(counter2);
      	    counter2++;
	    break;
    case 3: f2_c(counter2);
	    counter2++;
  	    break;
    case 4: f2_d(counter2);
	    counter2++;
	    break;
    case 5: timer = millis()%100000;
      	    if(timer -prev2>=period2) {
		counter2=1;
		prev2=timer;
	    }
			
	    break;
	}
}

void f3() {

  long period3 = 10000;
  switch (counter3)
  {
    case 1: f3_a(counter3);
    	    counter3++;
	    break;
    case 2: f3_b(counter3);
  	    counter3++;
	    break;
    case 3: f3_c(counter3);
	    counter3++;
	    break;
    case 4: timer = millis()%100000;
	    if(timer -prev3>=period3){
		counter3=1;
		prev3=timer;
	    }
					
	    break;
	}
}

	//inner functions
void f1_a(int counter) {

Serial.println("func 1 part a");

//Serial.println(System.currentTimeMillis());
delay(10);

}

void f1_b(int counter) {
Serial.println("func 1 part b");

//Serial.println(System.currentTimeMillis());
delay(10);
}

 void f1_c(int counter) {

Serial.println("func 1 part c");

//Serial.println(System.currentTimeMillis());
delay(10);
	}

 void f1_d(int counter) {

Serial.println("func 1 part d");

//Serial.println(System.currentTimeMillis());
delay(10);
	}

 void f1_e(int counter) {

Serial.println("func 1 part e");

//Serial.println(System.currentTimeMillis());
delay(5);
	}

	 void f2_a(int counter) {

		Serial.println("func 2 part a");
		
		//Serial.println(System.currentTimeMillis());
                delay(10);
		
	}

	 void f2_b(int counter) {

		Serial.println("func 2 part b");
	
		//Serial.println(System.currentTimeMillis());
		delay(10);
	}

	 void f2_c(int counter) {

		Serial.println("func 2 part c");

		//Serial.println(System.currentTimeMillis());
		delay(10);
	}
	void f2_d(int counter) {

		Serial.println("func 2 part d");
		
		//Serial.println(System.currentTimeMillis());
		delay(6);
	}

	 void f3_a(int counter) {

		Serial.println("func 3 part a");
	
		//Serial.println(System.currentTimeMillis());
		delay(10);
	}

	 void f3_b(int counter) {

		Serial.println("func 3 part b");
	
		//Serial.println(System.currentTimeMillis());
		delay(10);
	}

	 void f3_c(int counter) {

		Serial.println("func 3 part c");
	
		//Serial.println(System.currentTimeMillis());
		delay(5);
	}

	

	
	

